//
//  HEIMInfoVideoPageCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2021/3/3.
//  Copyright © 2021 honglutec. All rights reserved.
//

#import "HEIMInfoVideoPageCell.h"

@interface HEIMInfoVideoPageCell ()

@property(nonatomic, strong) UIImageView *logoView;
@property(nonatomic, strong) UILabel *titleLb;
@property(nonatomic, strong) UILabel *descLb;

@end

@implementation HEIMInfoVideoPageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
   if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
       
       self.selectionStyle = UITableViewCellSelectionStyleNone;
 
       [self initUI];
       [self makeGesture];
   }
   return self;
}

- (void)makeGesture {
    [super makeGesture];
    UITapGestureRecognizer *contentTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contentClick)];
    [self.bubbleView addGestureRecognizer: contentTap];
}

- (void)contentClick {
    if ([self.delegate respondsToSelector:@selector(onTapMessage:)]) {
        [self.delegate onTapMessage: self.model.message];
    }
}

- (void)initUI {
    _logoView = [UIImageView new];
    [self.bubbleView addSubview:_logoView];
    
    UIButton *_playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _playBtn.userInteractionEnabled = NO;
    [_playBtn setImage:[UIImage imageNamed:@"new_allPlay_44x44_"] forState:UIControlStateNormal];
    [_logoView addSubview:_playBtn];
    
    _titleLb = [UILabel new];
    _titleLb.text = @"-";
    _titleLb.font = DYBlodFont(16);
    _titleLb.numberOfLines = 2;
    [self.bubbleView addSubview:_titleLb];
    
    _descLb = [UILabel new];
    _descLb.numberOfLines = 3;
    _descLb.text = @"-";
    _descLb.font = DYFont(15);
    _descLb.textColor = CNavDargGrayColor;
    [self.bubbleView addSubview:_descLb];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bubbleView).offset(15);
        make.left.equalTo(self.bubbleView).offset(15);
        make.right.equalTo(self.bubbleView).offset(-15);
    }];
    [_titleLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    
    [_logoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).offset(5);
        make.width.height.offset(60);
        make.right.equalTo(self.bubbleView).offset(-15);
        make.bottom.equalTo(self.bubbleView).offset(-15);
    }];
    
    [_playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.equalTo(_logoView);
        make.width.height.equalTo(_logoView.mas_width).multipliedBy(0.5);
    }];
    
    [_descLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_logoView.mas_top);
        make.left.equalTo(self.bubbleView).offset(15);
        make.right.equalTo(_logoView.mas_left).offset(-10);
        make.height.mas_lessThanOrEqualTo(_logoView.mas_height);
    }];
     
}

- (void)configCellWithModel:(HEIMMessageModel *)model {
    HEIMInfoPageObject *infoObject = (HEIMInfoPageObject *)model.message.messageObject;

    _titleLb.text = infoObject.title;
    _descLb.text = infoObject.subTitle;

    _titleLb.textColor = model.warpTextColor;
    _descLb.textColor = model.warpTextColor;

    [_logoView sd_setImageWithURL:infoObject.iconURL placeholderImage:IMAGE_NAMED(@"noImage")];
    
    [_titleLb mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(220);
    }];

    // 必须写
    [self refreshData:model];
}

@end
